$(document).ready(function(){
	$(".submit-holder").on("click",function() {
		if(validate()){
			console.log("ok")
			var email=$("#regEmail").val();
			var password=$("#regPassword").val();
			createStudio(email,password);
		}else{
			console.log("not ok")
			return
		}

	});
});
function validate () {
	var ok=true;
	var email=$("#regEmail").val();
	var password1=$("#regPassword").val();
	var password2=$("#regPassword2").val();
	if(/[_a-zA-Z\d\-\./]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+/.test(email)==false){
		ok=false;
		$(".error_email").text("邮箱格式不对")
	}
	if(password1!=password2){
		ok=false;
		$(".error_password").text("密码不一致")
	}
	return ok;
}
function createStudio (eml,psw) {
	$.ajax({
		url:config.api.createStudio[0],
		type:config.api.createStudio[1],
		data:{
			email:eml,
			password:psw
		},
		success:function (argument) {
			alert("成功注册");
			window.location.href="login.html";
		},
		error:function (argument) {
			if ( argument.responseJSON.err === 7001 ) {
				alert("该账号已被注册");
			} else {
				alert("注册失败");
			}
		}
	});
}
